package com.drdj.exam;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		Bundle bundle = intent.getExtras();
		SmsMessage[] msga = null;
		String str = "";

		if (bundle != null) {
			Object[] pdus = (Object[]) bundle.get("pdus");
			msga = new SmsMessage[pdus.length];

			for (int i = 0; i < msga.length; i++) {
				msga[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
				str +=  msga[i].getOriginatingAddress() + "\n";
				str += msga[i].getMessageBody().toString() + "\n";
				
			}
			
			Toast.makeText(context, str, Toast.LENGTH_LONG).show();
		}

	}

}
